<template>
  <div class="t-checkbox">
    <el-checkbox-group
      ref="checkBox"
      v-model="moduleValue"
      :disabled="disabled"
      @change="handleChange"
    >
      <el-checkbox
        v-for="item in options"
        :key="item.value"
        :label="item.value"
        >{{ item.label }}</el-checkbox
      >
    </el-checkbox-group>
  </div>
</template>
<script>
export default {
  name: "TCheckBox",
  props: {
    value: {
      type: String,
      default: "",
      require: true,
    },
    options: {
      type: Array,
      default: () => [],
    },
    disabled: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {};
  },
  computed: {
    moduleValue: {
      get() {
        return this.value ? this.value.split(",") : [];
      },
      set(val) {
        this.$emit("input", val?.length ? val.join(",") : "");
      },
    },
  },
  methods: {
    focus() {
      const select = this.$refs.select;
      if (select) {
        select.focus();
      }
    },
    handleChange(value) {
      this.$emit("change", value || []);
    },
  },
};
</script>
<style lang="scss" scoped>
.t-checkbox {
  .el-checkbox-group {
    display: flex;
    justify-content: space-around;
  }
}
</style>
